package ca.nfb.media.nfbPlayer.views
{
	import ca.nfb.media.nfbPlayer.ComModule;
	import ca.turbulent.media.Pyro;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class FullModalView extends NFBPlayerView
	{
		private var _backgroundAlpha	:Number = .65;
		public var blocksMouseEvents	:Boolean = true;
		public var overlapControls		:Boolean = true;
		public var isRunning			:Boolean = false;
		
		public function FullModalView(blockMouse:Boolean=true, overlapCtrl:Boolean=true)
		{
			super();
			blocksMouseEvents = blockMouse;
			overlapControls = overlapCtrl;
		}
		
		override protected function addedToStage(evt:Event):void 
		{ 
			registerStageEvents();
			this.visible = false;
		}
		
		public function startModal():void
		{
			
			this.addEventListener(Event.ENTER_FRAME, rotateArrow, false, 0, true);
			background_mc.alpha = this._backgroundAlpha;
			
			if (this.blocksMouseEvents)
				this.setProperties([background_mc], {mouseEnabled:true});
			
			background_mc.width = stage.stageWidth;
			if (this.overlapControls)	
				background_mc.height = stage.stageHeight;
			else
				background_mc.height = stage.stageHeight-core.controllerHeight;
	
			
			isRunning = true;
		
			arrow_mc.x =  background_mc.x + stage.stageWidth/2;
			arrow_mc.y = (stage.stageHeight-core.controllerHeight)/2;
			this.visible = true;
		}
		
		private function rotateArrow(evt:Event=null):void
		{
			MovieClip(arrow_mc).rotation -= 7;
		}
		
		public function stopModal():void
		{
			if (this.hasEventListener(Event.ENTER_FRAME))
				this.removeEventListener(Event.ENTER_FRAME, rotateArrow);
			
			isRunning = false;
			this.setProperties([background_mc], {mouseEnabled:false});
			this.visible = false;
		}
		
		public function reset():void
		{
			this.stopModal();
			this.startModal();
		}
		
		public function set backgroundAlpha(a:Number):void
		{
			_backgroundAlpha = a;
			
			if (isRunning)
				reset();
		}	
		
		
	}
}